import threading,time
#python 还提供了2个多线程接口 thread 提供底层接口。threading提供高等级接口
def func2(n):
    print('thread {} starts'.format(threading.current_thread().name))
    time.sleep(2)#########sleep期间，另一个线程可以交替执行（多线程是并发的，但不是并行的）
    print('thread {} ends'.format(threading.current_thread().name))
    return n
if __name__ == '__main__':
    print('main thread is {}'.format(threading.current_thread().name))
    start_time = time.time()
    ### multithread
    t1 = threading.Thread(target=func2, args=(1,))
    t2 = threading.Thread(target=func2, args=(2,))
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    end_time = time.time()
    print('total time is {}'.format(str(end_time - start_time)))

